package com.stylefeng.guns.modular.hhtb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.modular.hhtb.model.LogPuresAccualDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.hhtb.model.LogPurseAccrual;
import com.stylefeng.guns.modular.hhtb.service.ILogPurseAccrualService;

import java.util.List;
import java.util.Map;

/**
 * 理财钱包利息流水控制器
 *
 * @author fengshuonan
 * @Date 2018-08-30 09:54:07
 */
@Controller
@RequestMapping("/logPurseAccrual")
public class LogPurseAccrualController extends BaseController {

    private String PREFIX = "/hhtb/logPurseAccrual/";

    @Autowired
    private ILogPurseAccrualService logPurseAccrualService;

    /**
     * 跳转到理财钱包利息流水首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "logPurseAccrual.html";
    }

    /**
     * 跳转到添加理财钱包利息流水
     */
    @RequestMapping("/logPurseAccrual_add")
    public String logPurseAccrualAdd() {
        return PREFIX + "logPurseAccrual_add.html";
    }

    /**
     * 跳转到修改理财钱包利息流水
     */
    @RequestMapping("/logPurseAccrual_update/{logPurseAccrualId}")
    public String logPurseAccrualUpdate(@PathVariable Integer logPurseAccrualId, Model model) {
        LogPurseAccrual logPurseAccrual = logPurseAccrualService.selectById(logPurseAccrualId);
        model.addAttribute("item",logPurseAccrual);
        LogObjectHolder.me().set(logPurseAccrual);
        return PREFIX + "logPurseAccrual_edit.html";
    }

    /**
     * 获取理财钱包利息流水列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(LogPuresAccualDto logPuresAccualDto) {

        Page<Map<String,Object>> page = new PageFactory<Map<String,Object>>().defaultPage();
        List<Map<String, Object>>articlesList= logPurseAccrualService.accuAllist(page,logPuresAccualDto);
        page.setRecords(articlesList);
        return super.packForBT(page);
    }

    /**
     * 新增理财钱包利息流水
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LogPurseAccrual logPurseAccrual) {
        logPurseAccrualService.insert(logPurseAccrual);
        return SUCCESS_TIP;
    }

    /**
     * 删除理财钱包利息流水
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer logPurseAccrualId) {
        logPurseAccrualService.deleteById(logPurseAccrualId);
        return SUCCESS_TIP;
    }

    /**
     * 修改理财钱包利息流水
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LogPurseAccrual logPurseAccrual) {
        logPurseAccrualService.updateById(logPurseAccrual);
        return SUCCESS_TIP;
    }

    /**
     * 理财钱包利息流水详情
     */
    @RequestMapping(value = "/detail/{logPurseAccrualId}")
    @ResponseBody
    public Object detail(@PathVariable("logPurseAccrualId") Integer logPurseAccrualId) {
        return logPurseAccrualService.selectById(logPurseAccrualId);
    }
}
